<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$this->model('model')->add_dayredfee();
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'分销列表'),
);
set_html('tabs',$tabs);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['orderid']){
		$params['orderid']=$_RQ['orderid'];
		$return['params']['orderid']=$_RQ['orderid'];
	}
	if($_RQ['psize']){
		$_SESSION['psize']=$_RQ['psize'];
	}
	$psize = $_SESSION['psize']?:20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('commission',$parameter,$total);
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['level_id']=$this->getcolumn('member',array('mid'=>$item['mid']),'level_id');
			$ordermid=pdo_getcolumn('jy_weishop_order',array('id'=>$item['orderid']),'mid');
			$item['ordermember']=cfc('core')->member_show($ordermid);
			$item['address']=pdo_getcolumn('core_area',array('code'=>$item['area_code']),'address');
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'list'=>array('data'=>'list','tip'=>'完成后订单才能结算！','edit'=>false,'total'=>$total,'psize'=>$psize,'list'=>array(
			array('name'=>'member','title'=>'分销人','type'=>'member'),
			array('name'=>'level_id','title'=>'分销人等级','type'=>'select','options'=>'levels'),
			array('name'=>'orderid','title'=>'订单id','type'=>'string'),
			array('name'=>'ordermember','title'=>'下单人','type'=>'member'),
			array('name'=>'money','title'=>'佣金','type'=>'string'),
			array('name'=>'type','title'=>'分销类型','type'=>'radio','options'=>'types'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
			array('name'=>'status','title'=>'分销状态','type'=>'radio','options'=>'commission_status'),			
			array('name'=>'balancesn','title'=>'结算单号','type'=>'string'),
		)),
		'search'=>array(
			array('type'=>'string','width'=>15,'name'=>'orderid','title'=>'订单号'),
			array('type'=>'choose','width'=>18,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
			array('type'=>'radio','width'=>15,'name'=>'status','title'=>'分销状态','options'=>'commission_status'),
		),
	);
	$return['htmls']=$htmls;
	$return['types']=$this->fen_type;
	$return['levels']=$this->getall('level',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['commission_status']=$this->commission_status;
	exi($return);
}
if($_RQ['op']=='del'){

	$id=intval($_RQ['id']);
	if($id){
		$this->delete('commission',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				$this->delete('commission',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}